import React, { Component , PureComponent} from 'react';
import {UserList} from '../../components';
import {userAction} from '../../actions';
import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';
import { Link } from 'react-router-dom';
import { userService } from '../../service'


//连接state到props
const mapStateToProps = state => {
    console.log("hhhhhhhhhhhhhhhhhhhhhh");
    console.log(state);
    //console.log(state.getIn(['dish', 'userReducer']));
    return{
        userData: state.userReducer
    }
}

const mapDispatchToProps = (dispatch) =>{
    //console.log(userAction);
    return{
        actions:bindActionCreators(userAction,dispatch),
        dispatch:dispatch
    }
}


@connect(
    state => ({ 
        userData: state.userReducer 
    }),
    dispatch => ({
        actions:bindActionCreators(userAction,dispatch),
        dispatch:dispatch
    })
    //mapStateToProps,mapDispatchToProps
)

class User extends PureComponent {

    constructor (props) {
        super(props)
    }

    componentDidMount() {
        console.log(this.props);
        console.log("----------------user页面加载完成-----------------");
        const {selUser} = this.props.actions;
        //渲染后加载service查询方法
        userService.selUserAll(null,selUser);
    }


    render() {
        console.log("-----------user渲染----------")
        console.log(UserList);
        return (
            <div>
                <Link to="/dept"><button>dept</button></Link><Link to="/user"><button>user</button></Link>
                <UserList actions = {this.props.actions} userData = {this.props.userData}/>
            </div>
        )
    }
    
}



// export default connect(
//     mapStateToProps,mapDispatchToProps
// )(User);

export default User;